// components/capsule/index.js
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    moveFlag:{
      type:Boolean,
      value:false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    slidingFlag:false,
    boundButtonRect:{},
    cspHeight:app.globalData.menuHeight,
    topMargin:wx.getMenuButtonBoundingClientRect().top
  },
  observers:{
    'moveFlag': function (moveFlag) {
      // this._freshing = isRefresh
      if(moveFlag){
        // console.log('来了')
        this.setData({
          slidingFlag : true
        })
      }else{
        // console.log('该走了')
        this.setData({
          slidingFlag : false
        })
      }
    }
  },
  /**
   * 组件的方法列表
   */
  lifetimes: {
    attached: function () {
      // 在组件实例进入页面节点树时执行
      this.getBoundButtonRect()
      // console.log(this.data.cspHeight)
    },
    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    },
  },
  methods: {
    getBoundButtonRect:function(){
      let data = wx.getMenuButtonBoundingClientRect()
      const screenWidth =  app.globalData.screenWidth 
      let left = screenWidth - data.right
      let top = data.top
      let height = data.height
      let width = data.width
      this.setData(
        {
           boundButtonRect: {
             left,
             height,
             top,
             width
           }
        }
      )
    },
    goBack(){
      wx.navigateBack()
    },
    goHome:function(){
      wx.switchTab({
        url: '/pages/home/main/index'
      })
    }
  }
})
